package test2;


import com.easyaop.commons.MyLoader;

import java.io.File;
import java.io.FileOutputStream;

public class ToClassFile {
    public static void main(String[] args) throws Exception {

        Class<?> dumpClass = Class.forName("asm." + AsmDump.TARGET_CLASS.getName() + "Dump");
        byte[] dumps = (byte[]) dumpClass.getMethod("dump").invoke(null);

        File file = new File("aop-asm-impl/target/dump/"+ YewuBean.class.getName().replaceAll("\\.","/")+".class");
        file.getParentFile().mkdirs();
        System.out.println(file.getCanonicalFile());
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(dumps);
        fos.close();

        MyLoader myLoader = new MyLoader(ToClassFile.class.getClassLoader());
        Class<?> aClass = myLoader.loadClass(YewuBean.class.getName(), dumps);
        aClass.newInstance();
        aClass.getDeclaredMethod("main", String[].class)
                .invoke(null, new Object[]{null});

    }
}
